#include "RenzoInput.h"
namespace Renzo {
Input::Input(const char* file)
{
	// open
	f = fopen(file, "r");
	if (f == NULL) {
		rzSevere(ERROR_FILE_NOT_FOUND, file);
	}	

	// read all content into memory
	// adopted from http://www.cplusplus.com/reference/clibrary/cstdio/fread/
	// obtain file size
	fseek(f, 0, SEEK_END);
	size = ftell(f);
	rewind(f);

	// allocate memory to contain the whole file:
	buffer = (char*) malloc (sizeof(byte) * size);
	if (buffer == NULL) {rzError(ERROR_MEMORY_ALLOC); exit(EXIT_MEMORY_ALLOC);}

	// copy the file into the buffer:
	int result = fread(buffer, 1, size, f);
	if (result != size) {rzError(ERROR_FILE_READ); exit(EXIT_FILE_READ);}

	// reset data pointer
	pBuf = buffer;
}

Input::~Input(void)
{
	if (f != NULL) {
		fclose(f);
		f = NULL;
	}
}

bool Input::hasNext() {
	return true;
}

byte Input::nextByte() {
	return 0;
}
}